package ygw.study.designPatterns.builder;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 创建一个 Meal 类，带有上面定义的 Item 对象。
 * </p>
 * <p>
 * Copyright:2021.All rights reserved.
 * </p>
 * <p>
 * Company:Zsoft
 * </p>
 * <p>
 * CreateDate:2021-10-20 09:48
 * </p>
 *
 * @author YuGongWen
 * @history Mender:YuGongWen；Date:2021-10-20 09:48；
 */
public class Meal {
    private List<Item> items = new ArrayList<Item>();

    public void addItem(Item item){
        items.add(item);
    }

    public float getCost(){
        float cost = 0.0f;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    public void showItems(){
        for (Item item : items) {
            System.out.print("Item : "+item.name());
            System.out.print(", Packing : "+item.packing().pack());
            System.out.println(", Price : "+item.price());
        }
    }
}